package com.rabc.web.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.rabc.web.entity.SysRole;
import com.rabc.web.entity.SysRoleMenu;
import com.rabc.web.mapper.SysMenuMapper;
import com.rabc.web.mapper.SysRoleMapper;
import com.rabc.web.mapper.SysRoleMenuMapper;
import com.rabc.web.service.SysRoleMenuService;
import com.rabc.web.service.SysRoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> implements SysRoleService {

    @Autowired
    private SysRoleMapper sysRoleMapper;


    @Autowired
    private SysRoleMenuMapper roleMenuMapper;

    public List<SysRole> selectRolesList(SysRole role) {
        List<SysRole> sysRoles = sysRoleMapper.selectRolesList(role);
        return sysRoles;
    }

    @Override
    public int grantPermissions(List<String> menuIds, String roleId) {
        roleMenuMapper.delete(new QueryWrapper<SysRoleMenu>().eq("role_id", roleId));
      //  int i = roleMenuMapper.updateMenuIdByRoleIdAfter(menuId, roleId);
        int i = roleMenuMapper.insertMenuIds(menuIds, roleId);
        return i;
    }

}
